package com.bw.day03.address

import android.os.Bundle
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.recyclerview.widget.LinearLayoutManager
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.bw.base.net.mvvm.BaseActivity
import com.bw.day03.R
import com.bw.day03.adapter.AddressAdapter
import com.bw.day03.databinding.ActivityAddressBinding

@Route( path = "/app/AddressActivity")
class AddressActivity : BaseActivity<ActivityAddressBinding, AddressViewModel>() {
    lateinit var addressAdapter: AddressAdapter
    override fun initView() {
        binding.btnAdd.setOnClickListener {
            ARouter.getInstance().build("/app/AddAddressActivity").navigation()
        }
        addressAdapter= AddressAdapter()
        binding.rvAddress.adapter=addressAdapter
        binding.rvAddress.layoutManager= LinearLayoutManager(this)
        viewModel.address(20,1)
    }

    override fun initData() {
        viewModel.dressSuccess.observe(this){
            if (it.code==200){
                addressAdapter.data.clear()
                addressAdapter.data.addAll(it.data.list)
                addressAdapter.notifyDataSetChanged()
            }
        }
    }

    override fun getViewModel(): Class<AddressViewModel> = AddressViewModel::class.java

    override fun getLayoutId(): Int = R.layout.activity_address

    override fun onResume() {
        super.onResume()
       viewModel.address(20,1)

    }
}